package main

import (
	"context"
	"fmt"
	"os"
	"path"
	"strings"
	"uploadmp4/db"
)

func ScanOldMP4File(ctx context.Context, folder string) {
	fmt.Println("scan", folder)
	entrys, err := os.ReadDir(folder)
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, entry := range entrys {
		if entry.IsDir() {
			continue
		}
		baseName := path.Base(entry.Name())
		if strings.HasPrefix(baseName, ".") {
			continue
		}
		if !strings.HasSuffix(baseName, ".mp4") {
			continue
		}
		mp4Name := path.Join(folder, entry.Name())
		db.SaveMp4ToDb(ctx, mp4Name)
	}
}
